<template>
  <div>
    <div :id="'barChart' + categoretype"></div>
  </div>
</template>
<script>
import * as echarts from "echarts";
import request from "@/utils/request";
export default {
  name: "",
  props: {
    categore: {
      type: String,
      default: ""
    },
    categoretype: {
      type: String,
      default: ""
    }
  },
  data() {
    return {};
  },

  methods: { 
    init(query) {
      request({
        url: "/api/xy_pj_student/Xy_pj_student/evalStatistics",
        method: "post",
        data: {
          categoreid: this.categore,
          categoretype: this.categoretype,
          coursemanageid: query.coursemanageid,
          manageid: query.manageid
        }
      }).then(res => {
        console.log(res, "chart");
        let XData = res.data.x;
        let YData = res.data.y;
        this.initCharts(XData, YData);
      });
    },
    initCharts(XData, YData) {
      var chartDom = document.getElementById(`barChart${this.categoretype}`);
      var myChart = echarts.init(chartDom);
      var option;
      option = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow"
          }
        },
        xAxis: {
          name: "分值",
          type: "category",
          data: XData
        },
        yAxis: {
          name: "人数",
          type: "value"
        },
        series: [
          {
            data: YData,
            type: "bar",
            showBackground: true,
            backgroundStyle: {
              color: "rgba(180, 180, 180, 0.2)"
            }
          }
        ]
      };
      option && myChart.setOption(option);
    }
  }
};
</script>
<style scoped lang="scss">
#barChart1,
#barChart2,
#barChart3,
#barChart4 {
  width: 100%;
  height: 320px;
}
</style>
